<?php
/*
厂商确认收货
*/
include('../conn.php');

// 需传参数 
$id = $_POST['id'];
// 需传参数 end

// 状态 
$state5 = 5; 
// 状态 end

// 时间 
$datetime = date("Y-m-d H:i:s");
// 时间 end

if ($id != '') {
	//更改退货单状态
	$query = mysql_query("UPDATE tuihuo set state=".$state5.",4time='".$datetime."' where id=".$id);
	//end
	
	//查询订单应付金额
	$sql = "SELECT b.accounts_payable, a.ordersid, b.userid FROM tuihuo AS a LEFT JOIN goodsorders AS b ON a.ordersid = b.ordersid WHERE id = " . $id;
	
	$order = mysql_fetch_assoc(mysql_query($sql));
	//end 
	
	//更新商户钱包金额
	$sql = "UPDATE USER SET money = money+" . $order['accounts_payable'] . " WHERE userid = " . $order['userid'];
	$res = mysql_query($sql);
	//end
	
	if (mysql_affected_rows()>0) {
		$arr = array('code' => 200, 'msg' => '厂商确认收货成功' );
	}else{
		$arr = array('code' => 201, 'msg' => '厂商确认收货失败，请重新提交' );
	}
}else{
	$arr = array('code' => 400, 'msg' => 'id不存在' );
}
echo json_encode($arr);